extends ../layout

block content
  .container
    #addUser.modal.fade
      .modal-dialog
        .modal-content
          form(method="POST", action="/user/signup/")
            .modal-header 用户管理
            .modal-body
              .form-group
                label(for="nickname") 昵称:
                input#nickname.form-control(name="nickname", type="text")
              .form-group
                label(for="signupPassword") 密码:
                input#signupPassword.form-control(name="password", type="password")
              .form-group
                label(for="email") 邮箱:
                input#email.form-control(name="email", type="text")
              .form-group
                label(for="phone") 手机:
                input#phone.form-control(name="phone", type="text")
              .form-group
                label(for="signinName") 权限:
                input#signinName.form-control(name="role", type="text")
            .modal-footer
              button.btn.btn-default(type="button", data-dismiss="modal") 关闭
              button.btn.btn-success#adduser(type="submit") 提交

    .modal(style='position: relative;top: auto;right: auto;left: auto;bottom: auto;z-index: 1;display: block; overflow: visible; max-width: 1000px; margin: 0 auto;')
      .modal-dialog(style='position:static; margin: 10px 20px; width:auto;')
        .modal-content
          .modal-header
            h4.modal-title
              | 用户管理   
          .modal-body
            table.table.table-bordered.table-hover.footable
              thead
                tr
                  div.form-group.pull-right(style="width:40%")
                    div.input-group
                      input.form-control#searchText(type='text', placeholder="用户名, 邮箱, 手机或其它...", value="")
                      div.input-group-btn
                        button.btn.btn-default#searchDongle(type="button") 搜索
                tr.footable-header
                  th.hidden
                  th 序号
                  th 昵称
                  th 邮箱
                  th 手机
                  if user.role>=100
                    th 权限
                    th 操作
                  th(data-hide="all") 用户昵称
                  th(data-hide="all") 用户权限
                  th(data-hide="all") 注册时间
              tbody
                for item,index in users
                    tr(id="item-id-#{item._id}")
                      th.hidden
                      td #{index+1}
                      td #{item.nickname}
                      td #{item.email}
                      td #{item.phone}
                      if user.role>=100
                        td #{item.role}
                        td
                          button.btn.btn-info.btn-xs(type="button", data-id="#{item._id}") 编辑
                          button.btn.btn-primary.btn-xs(type="button", data-id="#{item._id}") 日志
                          button.btn.btn-xs.btn-danger.del(type="button", data-id="#{item._id}") 删除
                      td #{item.nickname}
                      td
                        if item.role>=75
                          span 管理员
                        else if item.role>=50&&item.role<75
                          span 超级黄金会员
                        else if item.role>=25&&item.role<50
                          span 黄金会员
                        else if item.role>=10&&item.role<25
                          span 白银会员
                        else
                          span 普通会员
                      td #{moment(item.meta.updateAt).format('YYYY-MM-DD HH:mm:ss')}
          .modal-footer
            //- a.btn.btn-info.btn-mini(href="#",data-toggle="modal" ,data-target="#addUser")
            //-   .icon-plus 添加用户
            a.btn.btn-info.btn-mini(href="/user/edituser/")
              .icon-plus 添加用户

  center(style="color:#ccc;")
    | A demo by 
    a(href='http://buildlove.top') liyang 
    | Read the 
    a(href='https://github.com/buildlove/todos') todos 
  script.
    $('#adduser').click(function(){
      location.reload()
    })
    $('.del').click(function(e) {
      var id, target, tr;
      target = $(this);
      id = target.attr('data-id');
      tr = $('#item-id-' + id);
      tr.remove();
      return $.ajax({
        type: 'DELETE',
        url: '/user/del?id=' + id +'/'
      });
    });
    jQuery(function($){
      $('table.footable').footable();
    });
